package com.xxwy.ddu.cms.manager.controller;

import com.xxwy.ddu.cms.authonrize.entity.Access;
import com.xxwy.ddu.cms.authonrize.entity.RoleAccess;
import com.xxwy.ddu.cms.authonrize.service.IAccessService;
import com.xxwy.ddu.cms.authonrize.service.IRoleAccessService;
import com.xxwy.ddu.common.util.RUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xxwy
 * on 2018/9/17 0017
 */
@RestController
@RequestMapping("authorities")
public class AuthoritiesController {
    @Autowired
    IAccessService iAccessService;
    @Autowired
    IRoleAccessService iRoleAccessService;

    @GetMapping("/all")
    public ResponseEntity getAllAuthoritiesInfo(@RequestParam(required = false) Integer  rId){
        List<Access> allAccessInfo = iAccessService.getAllAccessInfo(rId);
        return RUtil.success(allAccessInfo);
    }

    @GetMapping("/access")
    public ResponseEntity insertAccess(@RequestParam Integer rId,@RequestParam Integer aId){
        RoleAccess roleAccess = new RoleAccess();
        roleAccess.setrId(rId);
        roleAccess.setaId(aId);
        iRoleAccessService.insertRoleAccess(roleAccess);
        return RUtil.success();
    }

    @DeleteMapping("/access")
    public ResponseEntity delectAccess(@RequestParam Integer rId,@RequestParam Integer aId){
        RoleAccess roleAccess = new RoleAccess();
        roleAccess.setrId(rId);
        roleAccess.setaId(aId);
        iRoleAccessService.delectRoleAccess(roleAccess);
        return RUtil.success();
    }
}
